#include "Soldier.h"
#include <stdio.h>

#include "SDL/SDL_log.h"
#include "SDL/SDL.h"

int showWindow(){
    if(SDL_Init(SDL_INIT_VIDEO)){
       SDL_Log("init error : %s", SDL_GetError());
       return 1;
    }
    SDL_Window *window = SDL_CreateWindow("title", 
                            SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                            800, 300, SDL_WINDOW_SHOWN);
    if(window == NULL){
       SDL_Log("create window error %s", SDL_GetError());
       return 2;
    }
  //  SDL_Delay(9000);
    //必须有事件处理，否则窗体出不来，
    while (1)
    {
       SDL_Event event;
       if(SDL_PollEvent(&event)){
            printf("event is %#x\n", event.type); // test code
            if (SDL_QUIT == event.type) {
                break;
            }
       }
    }
    SDL_DestroyWindow(window);
}

int main()
{
    Soldier *soldier = NULL;
    createSoldier(&soldier);//在createSoldier malloc 使用二级指针
    attack(soldier);
    destorySoldier(soldier);
    printf("attack finish %s\n", soldier->name);

    showWindow();
    return 0;
}